<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>欢迎页面-SpringCloud</title>
  <base href="/">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Access-Control-Allow-Origin" content="*" />
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="css/font.css">
  <link rel="stylesheet" href="css/xadmin.css">
  <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  <script type="text/javascript" src="js/xadmin.js"></script>
  <style type="text/css">
    .layui-laypage {
      margin-left: 35%;
      margin-top: 50px;
    }
    .checkItem{
      width: 19px;
      height: 19px;
    }
  </style>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
  <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
  <!--[endif]-->
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">系统管理</a>
        <a>
          <cite>学生管理_ribbon</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
  <div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" id="searchForm">
      <input type="text" name="bookName"  id="bookName" placeholder="请输入书名"  autocomplete="off" class="layui-input">
      <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
    </form>

  </div>
  <xblock id="userAddBtn">
    <button class="layui-btn" onclick="x_admin_show_full('添加书本','page/book-form_ribbon',800,500)"><i class="layui-icon"></i>添加</button>
  </xblock>
  <table class="layui-table">
    <thead>
    <tr>
      <th>
        <input type="checkbox" class="checkItem header">
      </th>
      <th>ID</th>
      <th>书本编号</th>
      <th>书名</th>
      <th>出版社</th>
      <th>作者</th>
      <th>价格</th>
      <th>推荐理由</th>
      <th>服务器</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
  </table>

  <div id="page"></div>
  <input type="hidden" id="pages">
  <input type="hidden" id="pageNum">

</div>
<script>
  if(localStorage.getItem("urls")==null){
    $("#userAddBtn").remove();
  }

  layui.use(['form','laypage'], function(){
    var form=layui.form;
    laypage = layui.laypage;
    //搜索框点击事件
    form.on('submit(search)',function(){
      initUserList();
      return false;
    });
    //初始化表格数据
    initUserList();
    $(document).on('click','.edit',function () {
      var userId=$(this).attr("link");
      //   alert("你想编辑学号为:"+userId+"的学生信息，但是编辑功能还没有完成！！");
      var index=x_admin_show('修改书本信息','page/book-form?id='+userId,800,500);
      layer.full(index);
      return false;
    });
    $(document).on('click','.delete',function () {
      var userId=$(this).attr("link");
      //  alert("你想删除学号为:"+userId+"的学生，但是删除功能还没有完成！！");
      $.ajax({
        contentType: "application/x-www-form-urlencoded",
        //  url:'user_hystric/delStudent/'+userId,
        url:'http://localhost:9527/proxy/api-consumer/book_ribbon/delBook/'+userId+'?accessToken=2',
        type:'get',
        success:function (res) {
          if(res.code==200){
            layer.msg("删除成功!",{icon:1,time:1000});
            initUserList($("#pageNum").val());
          }
        }
      });
      return false;
    });

  });

  function initUserList(pn,pageSize){
    //判断用户有无列表查询的权限
    // if(urlValidate("/user-get")>=0){
    if (localStorage.getItem("urls")!=null){
      $.ajax({
        contentType: "application/x-www-form-urlencoded",
        url:"http://localhost:9527/proxy/api-consumer/book_ribbon/findAllBooks?accessToken=2",
        //    url: "user_hystric/findAllStudents",
        data:{stuName:$("#stuName").val(),pn:pn,pageSize:pageSize},
        success:function(result){
          if(result.code==200){
            $(".layui-table tbody").empty();
            $.each(JSON.parse(result.data.pageInfo),function (index,item) {
              var td1=$("<td></td>").append(getCheckItem(item.id,item.stuName));
              var td2=$("<td></td>").append(item.id);
              var td3=$("<td></td>").append(item.bookId);
              var td4=$("<td></td>").append(item.bookName);
              var td5=$("<td></td>").append(item.publishing);
              var td6=$("<td></td>").append(item.author);
              var td7=$("<td></td>").append(item.price);
              var td8=$("<td></td>").append(item.recommend);
              var td9=$("<td></td>").append(item.serviceName);
              var td10=$("<td></td>").addClass("td-manage");
              if(localStorage.getItem("urls")!=null){
                td10.append(getEditItem(item.id,"edit"));
              }
              if(localStorage.getItem("urls")!=null){
                td10.append(getDeleteItem(item.id,"delete"));
              }
              $(".layui-table tbody").append($("<tr></tr>").append(td1).append(td2).append(td3).append(td4).append(td5).append(td6).append(td7).append(td8).append(td9).append(td10));
            });
            var pages=result.data.pageInfo.pages;//总页数
            var curr_page=result.data.pageInfo.pageNum;//当前页
            var counts=result.data.pageInfo.total;//总记录数
            $("#totals").text(counts);
            $("#pages").val(pages+1);
            $("#pageNum").val(curr_page);
            laypage.render({
              elem: 'page'
              ,count: counts //数据总数，从服务端得到
              ,pages: pages
              ,first: 1
              ,last:  pages
              ,curr:curr_page
              ,layout: ['prev','page','next','skip','count']
              ,jump: function(obj, first){
                //obj包含了当前分页的所有参数，比如：
                //首次不执行
                if(!first){
                  //do something
                  var toPage=obj.curr;
                  if(toPage!=curr_page){
                    initUserList(toPage);
                  }
                }
              }
            });
          }
        }
      });
    }else{
      $(".layui-table tbody").empty();
      $(".layui-table tbody").append('<tr><td colspan="4" align="center">你已经退出登录，请登录后查看相关数据</td></tr>');
    }
  }
</script>
</body>
</html>